<?php
/// ------------
/// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
/// ------------
/// | Copyright (c) 2006-2012 http:///thinkphp.cn All rights reserved.
/// ------------
/// | Licensed ( http:///www.apache.org/licenses/LICENSE-2.0 )
/// ------------
/// | Author: liu21st <liu21st@gmail.com>
/// ------------
/// $Id: ThinkException.class.php 2791 2012-02-29 10:08:57Z liu21st $

/**
 * ThinkPHP系统异常基类
 * @category   Think
 * @package  Think
 * @subpackage  Exception
 * @author    liu21st <liu21st@gmail.com>
 * @version   $Id: ThinkException.class.php 2791 2012-02-29 10:08:57Z liu21st $
 */
class JsonException extends Exception {

    /**
     * 异常类型
     * @var string
     * @access private
     */
    private $type;

    /// 是否存在多余调试信息
    private $extra;

    /**
     * 架构函数
     * @access public
     * @param string $message  异常信息
     */
    public function __construct($message,$code=0,$extra=false) {
    	is_array($message) && $message = implode('</br>',$message);
        parent::__construct($message,$code);
        $this->type = get_class($this);
        $this->extra = $extra;
    }

    /**
     * 异常输出 所有异常处理类均通过__toString方法输出错误
     * 每次异常都会写入系统日志
     * 该方法可以被子类重载
     * @access public
     * @return array
     */
    public function __toString() {
    	header('Content-Type:text/html; charset=utf-8');
    	if ($_POST['referer']=='js') {
    		$result  =  array();
    		$result['status']  =  0;
    		$result['info'] =  $this->message;
    		$result['data'] = $data;
    		exit(json_encode($result));
    	}else {
    		exit('<div class="prompt_div">'.$this->message.'</div>');
    	}
    }

}